package com.ymatou.iapi.ocr.testcase;

import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.ocr.parameter.DoOcrBean;
import com.ymatou.iapi.ocr.service.DoOcrCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.FontImage;
import com.ymttest.utils.TestDataManager;

/**
*图形识别
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DoOcr{
	private static DoOcrBean doocrBean;
	private static DoOcrCall doocrCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("图形识别");
	}

	@Before
	public void caseUp() {
		doocrBean=new DoOcrBean();
		doocrCall=new DoOcrCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(doocrCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DoOcr_001() {
		Logger.start(true,"传入单行图片识别成功");
		try {
			String p1="./temp/a.png";
			FontImage.createImage(p1,Arrays.asList("请A1003到3号窗口"), new Font("宋体", Font.BOLD, 30) , FontImage.getColorFmtAlpha(Color.ORANGE,0.8d), Color.WHITE);

			String up1=TestDataManager.UploadFile(p1);
			doocrBean.setImgUrl(up1);
			doocrBean.setLanguage("chi_sim");
			doocrCall.setData(doocrBean);
			doocrCall.callService();			
			Logger.verifyEquals(200, doocrCall.getStatusCode(), "提交成功");
			Logger.comment(doocrCall.getReturnData());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DoOcr_002() {
		Logger.start(true,"传入多行图片识别成功");
		try {
			String p1="./temp/a.png";
			FontImage.createImage(p1,Arrays.asList("请A1003到3号窗口","请A1002到2号窗口"), new Font("黑体", Font.PLAIN, 30), FontImage.getColorFmtAlpha(Color.BLUE,0.3d),Color.WHITE);

			String up1=TestDataManager.UploadFile(p1);
			doocrBean.setImgUrl(up1);
			doocrBean.setLanguage("chi_sim");
			doocrCall.setData(doocrBean);
			doocrCall.callService();	
			Logger.verifyEquals(200, doocrCall.getStatusCode(), "提交成功");
			Logger.comment(doocrCall.getReturnData());
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DoOcr_003() {
		Logger.start(true,"传入多行水印图片识别成功");
		try {
			String p1="./temp/a.png";
			List<String> info=new ArrayList<String>();
			for (int i = 0; i < 10; i++) {
				info.add("添加水印测试:"+i);
			}
			FontImage.addWaterMark("./resource/Penguins.jpg",p1,info,new Font("黑体", Font.PLAIN, 30), FontImage.getColorFmtAlpha(Color.RED,0.9d),"png");

			String up1=TestDataManager.UploadFile(p1);
			doocrBean.setImgUrl(up1);
			doocrBean.setLanguage("chi_sim");
			doocrCall.setData(doocrBean);
			doocrCall.callService();			
			Logger.verifyEquals(200, doocrCall.getStatusCode(), "提交成功");
			Logger.comment(doocrCall.getReturnData());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DoOcr_004() {
		Logger.start(true,"传入训练图片图片识别成功");
		try {
			String p1="./resource/test.973.jpg";
//			String p1="./temp/2.png";
			String up1=TestDataManager.UploadFile(p1);
			doocrBean.setImgUrl(up1);
			doocrBean.setLanguage("chi_sim");
			doocrCall.setData(doocrBean);
			doocrCall.callService();			
			Logger.verifyEquals(200, doocrCall.getStatusCode(), "提交成功");
			Logger.comment(doocrCall.getReturnData());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}